/**
 *
 */
package cc.rengu.igas.opms.common.util;

public class ChangeOrderStateUtil {

    /**
     * @Description: 将TPPS的支付状态改成OPMS的支付状态
     * @Author:
     * @CreateTime:
     * @param srcState  TPPS订单状态
     * @return destState OPMS订单状态
     */
    public static String OrderStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }

        /**
         * 0 – 未支付               00-新建订单
         1 – 支付成功             03-订单支付成功
         2 – 支付失败             04-订单支付失败
         4 – 已撤销               06-订单支付已撤销
         5 – 转入退款             07-订单支付已退款
         6 – 已关闭               05-订单关闭
         7 – 交易结束(不可退款)   05-订单关闭
         9 – 未知状态             02-订单待确认
         P – 用户支付中           01-订单支付中
         * */
        String destState = null;
        switch (srcState) {
            case "0":
                destState = "00";
                break;
            case "1":
                destState = "03";
                break;
            case "2":
                destState = "04";
                break;
            case "4":
                destState = "06";
                break;
            case "5":
                destState = "07";
                break;
            case "6":
            case "7":
                destState = "05";
                break;
            case "9":
                destState = "02";
                break;
            case "P":
                destState = "01";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

    /**
     * @Description: 将TPPS的支付状态改成OPMS的支付状态
     * @Author:
     * @CreateTime:
     * @param srcState  TPPS订单状态
     * @return destState OPMS支付状态
     */
    public static String PayStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }
        /**
         * 0 – 未支付               01-待支付
         1 – 支付成功             00-支付成功
         2 – 支付失败             02-支付失败
         4 – 已撤销                  02-支付失败
         5 – 转入退款             02-支付失败
         6 – 已关闭                  02-支付失败
         7 – 交易结束(不可退款)   02-支付失败
         9 – 未知状态            02-支付失败
         P – 用户支付中        02-支付失败
         * */
        String destState = null;
        switch (srcState) {
            case "0":
                destState = "01";
                break;
            case "1":
                destState = "00";
                break;
            case "2":
            case "4":
            case "5":
            case "6":
            case "7":
            case "9":
            case "P":
                destState = "02";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

    public static String WxOrderStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }

        /**
         * 0 – 未支付               00-新建订单
         1 – 支付成功             03-订单支付成功
         2 – 支付失败             04-订单支付失败
         4 – 已撤销               06-订单支付已撤销
         5 – 转入退款             07-订单支付已退款
         6 – 已关闭               05-订单关闭
         7 – 交易结束(不可退款)   05-订单关闭
         9 – 未知状态             02-订单待确认
         P – 用户支付中           01-订单支付中
         * */
        String destState = null;
        switch (srcState) {
            case "NOTPAY":
                destState = "01";
                break;
            case "SUCCESS":
                destState = "03";
                break;
            case "PAYERROR":
                destState = "04";
                break;
            case "REVOKED":
                destState = "06";
                break;
            case "CLOSED":
                destState = "05";
                break;
            case "USERPAYING":
                destState = "01";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

    public static String WxPayStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }
        /**
         * 0 – 未支付               01-待支付
         1 – 支付成功             00-支付成功
         2 – 支付失败             02-支付失败
         4 – 已撤销                  02-支付失败
         5 – 转入退款             02-支付失败
         6 – 已关闭                  02-支付失败
         7 – 交易结束(不可退款)   02-支付失败
         9 – 未知状态            02-支付失败
         P – 用户支付中        02-支付失败
         * */
        String destState = null;
        switch (srcState) {
            case "00":
                destState = "01";
                break;
            case "01":
                destState = "01";
                break;
            case "03":
                destState = "00";
                break;
            case "04":
            case "05":
            case "06":
                destState = "02";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

    public static String CupsWxOrderStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }

        /**
         * SUCCESS	00	支付成功                03-订单支付成功
         PAYERROR	01	支付失败     04-订单支付失败
         UNKNOWN	02	结果未知               02-订单待确认
         REFUND	03	转入退款               08-退款中
         NOTPAY	04	未支付                    00-新建订单
         CLOSED	05	已关闭                    05-订单关闭
         REVOKED	06	已撤销                    06-订单支付已撤销
         USERPAYING	07	支付中          01-订单支付中
         * */
        String destState = null;
        switch (srcState) {
            case "SUCCESS":
                destState = "03";
                break;
            case "PAYERROR":
                destState = "04";
                break;
            case "UNKNOWN":
                destState = "02";
                break;
            case "REFUND":
                destState = "08";
                break;
            case "NOTPAY":
                destState = "02";
                break;
            case "CLOSED":
                destState = "05";
                break;
            case "REVOKED":
                destState = "06";
                break;
            case "USERPAYING":
                destState = "01";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

    public static String CupsWxPayStateChange(String srcState) {
        if (srcState == null) {
            return null;
        }

        /**
         * SUCCESS	00	支付成功                00-支付成功
         PAYERROR	01	支付失败     02-支付失败
         UNKNOWN	02	结果未知               01-待支付
         REFUND	03	转入退款               02-支付失败
         NOTPAY	04	未支付                    01-待支付
         CLOSED	05	已关闭                    02-支付失败
         REVOKED	06	已撤销                    02-支付失败
         USERPAYING	07	支付中          01-待支付
         * */
        String destState = null;
        switch (srcState) {
            case "SUCCESS":
                destState = "00";
                break;
            case "UNKNOWN":
            case "USERPAYING":
            case "NOTPAY":
                destState = "01";
                break;
            case "PAYERROR":
            case "REFUND":
            case "CLOSED":
            case "REVOKED":
                destState = "02";
                break;
            default:
                destState = null;
                break;
        }
        return destState;
    }

}
